﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Microsoft.Reporting.WebForms;
using Ewts.Code;

namespace EWMSWeb.RDLC
{
    public partial class ProductionStorageItems : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                DateTime startdate = DateTime.Parse(Request["startDate"].ToString());
                DateTime enddate = DateTime.Parse(Request["endDate"].ToString()).AddDays(1).AddSeconds(-1);
                int flag = int.Parse(Request["flag"].ToString().Trim());
                string goodscode = Request["goodsCode"].ToString();
                string storageno = Request["storageno"].ToString();
                string belong = Request["belong"].ToString();
                string graphic = Request["graphic"].ToString();
                binddata(startdate, enddate, belong, graphic, goodscode, storageno, flag);
            }
        }

        protected void binddata(DateTime startdate, DateTime enddate, string belong, string graphic, string goodscode, string storageno, int flag)
        {
            DataLib.BLL.Productions bll = new DataLib.BLL.Productions();
            DataSet barCodeDS = new DataLib.BLL.BarCode().GetDsByWhere(startdate, enddate, belong, graphic, goodscode, storageno, flag);
            if (barCodeDS != null && barCodeDS.Tables[0].Rows.Count > 0)
            {
                barCodeDS.Tables[0].Columns.Add("CompanyName");
                string companyName = "";
                for (int i = 0; i < barCodeDS.Tables[0].Rows.Count; i++)
                {
                    if (barCodeDS.Tables[0].Rows[i]["cjoid"].ToString() != "0")
                    {
                        DataLib.Model.CJOItem cjoModel = new DataLib.BLL.CJOItem().GetListByCid(int.Parse(barCodeDS.Tables[0].Rows[i]["cjoid"].ToString()));
                        companyName = cjoModel.companyname;
                        barCodeDS.Tables[0].Rows[i]["CompanyName"] = companyName;
                    }

                }
            }

            ReportDataSource rds = new ReportDataSource("DataSet1", barCodeDS.Tables[0]);
            ReportViewer1.LocalReport.DataSources.Clear();
            new RDLCPrinter().FillRow(barCodeDS.Tables[0], 3, 20, 20);//为列表添加空行
            ReportViewer1.LocalReport.DataSources.Add(rds);
            ReportViewer1.LocalReport.Refresh();
        }

    }
}